#pragma once
#include <vector>
#include <iterator>
#include "tree.hh"
#include "XMLAttribute.h"
#include "XmlNodes.h"
#include "XmlAttributes.h"

#include <memory>
using namespace std;

// Forward declaration to avoid compile errors

class xml_document;
// This class encapsulates an xml node and 
// contains information like the child nodes 
// parent node and the attributes of an xml node
class xmlnode
{
public:	

	// Returns a xmlnodes collection of the children nodes of this node.
	xmlnodes get_child_nodes();

	// Gets the parent node of this node.
	std::shared_ptr<xmlnode> get_parent_node();

	// Returns a random access iterator to  the attributes of this node.
	const xmlattributes & get_attributes();

	// Returns a xmlnodes collection of sibling nodes
	xmlnodes get_sibling_nodes();

	// Returns the innertext of a xmlnode
	string get_innertext();

	// Gets the name associated with the node.
	std::string get_name();

protected:
	
	friend xml_document;

    // Sets the attributes for this node
	void set_attributes(xmlattributes & attributes);
	
    // Sets the node reference.
	void set_node_reference(tree_node_<std::shared_ptr<xmlnode>> * node);

	// Sets the inner text for this node.
	void set_innertext(string text);

	// Sets the name
	void set_name(const std::string & inName);
    

private:

	// A pointer referring to the node corresponding to this
	// node object in the tree used for representing the xml 
	tree_node_<std::shared_ptr<xmlnode>> * tree_node;
	
	// Holds all the attributes in this node
    xmlattributes attributes;	

	// Holds the innertext of an xml node
	string innertext;

	std::string name;
};
